$().ready(function() {

    var validator = $('#registerform').validate({
        //debug: true,
        errorElement: "div",
        onKeyup: true,
        submitHandler: function(form) {
            //alert("验证通过验证通过");
            form.submit();
            //return;
        },
        errorPlacement: function(error, element) {
            //error.appendTo(element.next());
            //alert("[发现错误]");

            $("#" + element[0].id).removeClass();
            $("#" + element[0].id + " ~ div").hide();
            $("#" + element[0].id + " ~ .error").show();



        },
        success: function(error, element) {
            //alert("[验证通过]");
            $("#" + element.id).removeClass();
            $("#" + element.id + " ~ div").hide();
            $("#" + element.id + " ~ .success").show();
        },
        rules: {
            username: {
                required: true,
                pattern: /^[a-zA-Z0-9_]{6,16}/,
                remote: {
                    url: "checkuser.py", //后台处理程序
                    type: "post", //数据发送方式
                    dataType: "json", //接受数据格式
                    data: { //要传递的数据
                        username: function() {
                            return $("#username").val();
                        }
                    }
                }

            },
            password: {
                required: true,
                pattern: /^[a-zA-Z0-9_]{6,16}/
            },
            confirmpassword: {
                required: true,
                pattern: /^[a-zA-Z0-9_]{6,16}/,
                equalTo: "#password",
            },
            registeragreement: { required: true }


        }
    });

    $("#butsub").attr("disabled", true);
    var dataList = ["0", "1"];
    var options = {
        dataList: dataList,
        success: function() {
            //console.log("OK"); 
            $("#butsub").attr("disabled", false);
        },
        fail: function() {
            //console.log("fail");  
            $("#butsub").attr("disabled", true);
        }
    };
    SliderBar("valimg", options);
});